include("shared.lua")

local Cars = {
Golf = { "models/vehicles/golf/golf.mdl", "Golf", "A quick get away!", "$60,000", "Golf", 60000, "scripts/golf.txt" },
Corvette = { "models/vehicles/corvette/corvette.mdl", "Corvette", "A quick get away!", "$200,000", "Corvette", 200000, "scripts/corvette.txt" },
Murcielago = { "models/vehicles/murcielago/murcielago.mdl", "Murcielago", "A quick get away!", "$350,000", "Mucielago", 350000, "scripts/murcielago.txt." }
}

function NPCMenu()	

surface.CreateFont( "Trebuchet24", 18, 1000, true, true, "CarDealer_Title3" )
surface.CreateFont( "Trebuchet24", 16, 1000, true, true, "CarDealer_Description3" )

local CarDealerFrame = vgui.Create( "DFrame" )
CarDealerFrame:SetSize( 600, 600 )
CarDealerFrame:SetTitle( "Chat Menu" )
CarDealerFrame:SetVisible( true )
CarDealerFrame:SetDraggable( false )
CarDealerFrame:ShowCloseButton( true )
CarDealerFrame:Center()
CarDealerFrame:MakePopup()

local CarDealerList = vgui.Create( "DPanelList", CarDealerFrame )
CarDealerList:SetPos( 10, 32 )
CarDealerList:SetSize( CarDealerFrame:GetWide() - 20, CarDealerFrame:GetTall() - 72 )
CarDealerList:SetSpacing( 2 )
CarDealerList:EnableHorizontal( false )
CarDealerList:EnableVerticalScrollbar( true )

local CarDealerButtonRemove = vgui.Create( "DButton", CarDealerFrame )
CarDealerButtonRemove:SetPos( 40, 570 )
CarDealerButtonRemove:SetSize( 125, 25 )
CarDealerButtonRemove:SetText( "Remove spawned car" )
CarDealerButtonRemove.DoClick = function()
	LocalPlayer():ConCommand( "_removecar_" )
end

for k,v in pairs( Cars ) do

	local CarDealerPanel = vgui.Create( "DPanel", CarDealerList )
	CarDealerPanel:SetSize( CarDealerList:GetWide(), 90 )
	CarDealerPanel.Paint = function()
		draw.RoundedBox( 8, 5, 3, CarDealerPanel:GetWide() - 10, CarDealerPanel:GetTall() - 10, Color( 100, 95, 95, 255 ))
	end
		
		local CarDealerIcon = vgui.Create( "SpawnIcon", CarDealerPanel )
		CarDealerIcon:SetPos( 25, 10 )
		CarDealerIcon:SetModel( v[1] )
		
		local CarDealerName = vgui.Create( "DLabel", CarDealerPanel )
		CarDealerName:SetColor( Color( 0, 255, 0, 255 ) )
		CarDealerName:SetFont( "CarDealer_Title3" )
		CarDealerName:SetPos( 100, 10 )
		CarDealerName:SetText( v[2] )
		CarDealerName:SizeToContents()
		
		local CarDealerDescription = vgui.Create( "DLabel", CarDealerPanel )
		CarDealerDescription:SetColor( Color( 255, 255, 255, 255 ) )
		CarDealerDescription:SetFont( "CarDealer_Description3" )
		CarDealerDescription:SetPos( 100, 30 )
		CarDealerDescription:SetText( v[3] )
		CarDealerDescription:SizeToContents()
		
		local CarDealerButton = vgui.Create( "DButton", CarDealerPanel )
		CarDealerButton:SetPos( 100, 50 )
		CarDealerButton:SetText( "Buy/Spawn" )
		CarDealerButton.DoClick = function()
			local CarDealerOptions = DermaMenu()
			CarDealerOptions:AddOption( "Buy", function() LocalPlayer():ConCommand( "_buycar_ "..v[5].." "..v[6] ) end )
			CarDealerOptions:AddOption( "Spawn", function() LocalPlayer():ConCommand( "_spawncar_ "..v[5].." "..v[1].." "..v[7] ) end )
			CarDealerOptions:Open()
		end
		CarDealerList:AddItem( CarDealerPanel )
	end
end

usermessage.Hook("CarDealerUsed", NPCMenu)